import json

import pymysql

#
def get_connection():
    con = pymysql.connect(
        host='localhost',
        user='root',
        password='root',
        port=3306,
        charset='utf8',
        database='test'
    )
    return con

def select(nameStr):
    name=nameStr
    sql = 'select * from feature_path_t where feature_name=%s'
    mysql = get_connection()
    db = mysql.cursor()
    try:
        db.execute(sql,name)
        res=db.fetchall()
        users=[]
        for r in res:
            user ={}
            user['id']=r[0]
            user['feature_name']=r[1]
            user['img_path_prefix']=r[2]
            users.append(user)
            print('查询成功')
        jsonStr = json.dumps(users)
        return jsonStr
    except Exception as e:
        print('操作失败',e)
        mysql.rollback()
    finally:
        db.close()
        mysql.close()

if __name__=='__main__':
    res = select("vgg_featureCNN-plus1.h5")
    print(res)